<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>判断多边形是否存在交叉</title>
</head>
<body>
    <script src="./turfjs/turf.min.js"></script>
    <script src="./utils/judgeTruePolygon.js"></script>
    <script>
        // 坐标点集合, 仅为demo，展示高高德坐标信息样式
        var _polygonArr = [
            {className: 'AMap.LngLat', kT: 35.968702295818794, KL: 120.15514334121701, lng: 120.155143, lat: 35.968702},
            {className: 'AMap.LngLat', kT: 35.968702295818794, KL: 120.17235239425662, lng: 120.172352, lat: 35.968702},
            {className: 'AMap.LngLat', kT: 35.95998382730498, KL: 120.16720255294803, lng: 120.167203, lat: 35.959984},
            {className: 'AMap.LngLat', kT: 35.96258904822142, KL: 120.15557249465945, lng: 120.155572, lat: 35.962589},
            {className: 'AMap.LngLat', kT: 35.96561099681334, KL: 120.17527063766482, lng: 120.175271, lat: 35.965611}
        ];           

        var _polygonArrTemp = [];

        // 纯坐标点集合 - 存在交叉
        var _polygonArrTemp1 = [
            [120.155143, 35.968702],
            [120.172352, 35.968702],
            [120.167203, 35.959984],
            [120.155572, 35.962589],
            [120.175271, 35.965611]
        ];
        // 纯坐标点集合 - 不存在交叉
        var _polygonArrTemp2 = [
            [120.155143, 35.968702],
            [120.172352, 35.968702],
            [120.167203, 35.959984],
            [120.155572, 35.962589],
            [120.151624, 35.966201]
        ];

        // 是否是正常多边形
        var _isTruePolygon = false;
        var _isTruePolygon1 = false;
        var _isTruePolygon2 = false;

        // 判断方法需要纯数据，过滤不必要信息，如果集合符合要求，则不需要这一步
        // _polygonArr.forEach((item) => _polygonArrTemp.push([item.getLng(), item.getLat()]));

        // 判断是否存在交叉
        // _isTruePolygon = isTruePolygon(_polygonArrTemp);
        _isTruePolygon1 = isTruePolygon(_polygonArrTemp1);
        _isTruePolygon2 = isTruePolygon(_polygonArrTemp2);
        
        // console.log('_isTruePolygon---->', _isTruePolygon);
        console.log('_isTruePolygon1---->', _isTruePolygon1);
        console.log('_isTruePolygon2---->', _isTruePolygon2);

    </script>
</body>
</html>